package com.zjhd.sealcutting.controller;

import com.zjhd.sealcutting.domain.WorksComment;
import com.zjhd.sealcutting.service.WorksCommentService;
import com.zjhd.sealcutting.utils.OperLog;
import com.zjhd.sealcutting.utils.response.ResponseResult;
import com.zjhd.sealcutting.utils.response.ResultGenerator;
import com.zjhd.sealcutting.vo.WorksCommentVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO 作品评论管理
 *
 * @author wangchao
 * @version 1.0
 * @date 2020/12/3 15:46
 */
@Api(value = "作品评论管理", tags = "作品评论管理")
@RequestMapping("/worksComment")
@RestController
public class WorksCommentController {

    private final static Logger logger = LoggerFactory.getLogger(WorksCommentController.class);

    @Autowired
    private WorksCommentService worksCommentService;

    @ApiOperation(value = "新增作品评论", notes = "新增作品评论接口")
    @PostMapping("/insertWorksComment")
    @OperLog(operModul = "作品评论管理-新增作品评论",operType = "新增",operDesc = "新增作品评论")
    public ResponseResult insertWorksComment(@RequestBody WorksComment worksComment){
        try{
            return ResultGenerator.genSuccessResult(worksCommentService.insertWorksComment(worksComment));
        }catch (Exception ex) {
            logger.error("新增作品评论接口失败", ex);
            return ResultGenerator.genFailResult("新增作品评论接口失败");
        }
    }

    @ApiOperation(value = "根据作品ID查询作品评论", notes = "根据作品ID查询作品评论接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "workId", value = "作品ID", dataType = "String", paramType = "query")
    })
    @GetMapping("/queryByWorkIdComment")
    public ResponseResult<List<WorksCommentVo>> queryByWorkIdComment(String workId){
        try{
            return ResultGenerator.genSuccessResult(worksCommentService.queryByWorkIdComment(workId));
        }catch (Exception ex) {
            logger.error("根据作品ID查询作品评论接口失败", ex);
            return ResultGenerator.genFailResult("根据作品ID查询作品评论接口失败");
        }
    }
}
